<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>在 JavaScript 行内创建工作者线程</title>
</head>
<body>
  <script>
    function fibonacci(n) {
      return n < 1 ? 0
        : n <= 2 ? 1
          : fibonacci(n - 1) + fibonacci(n - 2);
    }
    const workerScript = `self.postMessage(${fibonacci.toString()}(9));`;
    const worker = new Worker(URL.createObjectURL(new Blob([workerScript])));
    worker.onmessage = ({ data }) => console.log(data);
    // 34
  </script>
</body>
</html>